<template>
	<view>

		<view class="">
			<view style="width: 80px;">
				<button @click="on_upkey" class="f-14" style="padding: 0;">上传</button>
			</view>
		</view>

	</view>
</template>

<script type="text/javascript">
	import $C from '@/common/banmi/config.js';

	export default {
		name: 'up-img',
		props: {
			count: {
				//最多数量
				type: Number | String,
				default: 9
			},
			t_type: {
				//类型
				type: Number | String,
				default: 'images'
			},
			field: {

				type: Number | String,
				default: ''
			},
			val: {

				type: Number | String,
				default: ''
			},
			name: {

				type: Number | String,
				default: ''
			},
			list: {
				type: Number | String | Object | Array,
				default: ''
			},
		},
		data() {
			return {
				tempFilePath: '',
				t_name: '',
				imgList: [],
				img_url: ''
			}
		},
		mounted() {

		},
		methods: {
			on_upkey() {
				let that = this;
				uni.chooseFile({
					count: 1,
					success: function(res) {
						that.on_up_ajax(res.tempFilePaths[0]);
					}
				});
			},
			on_up_ajax(result) {
				 
				if (process.env.NODE_ENV === 'development') {
					var url = '/api/admin.php/admin.Upload/upload_key'
				} else {
					var url = $C.baseUrl + '/admin.Upload/upload_key';
				}

				let that = this;
				uni.uploadFile({
					url: url,
					filePath: result,
					name: 'file',
					formData:this.Http.get_data({}),
					success: (uploadFileRes) => {
						var dataString = uploadFileRes.data
						var dataObject = JSON.parse(dataString);
						if (dataObject.status == 200) {
							uni.showToast({
								title: dataObject.msg,
								icon: 'success'
							})
							var pem = dataObject.data.url
							that.confirm(pem)
							return
						}
						uni.showToast({
							title: dataObject.msg + dataObject.data,
							icon: 'none',
							duration: 5000
						})

					}
				});
			},
			confirm(pem) {
				this.$emit('confirm', pem, this.field, this.val, this.name)
			},



		}
	}
</script>
<style scoped>
	/* 	button {
		background-color: transparent;
	}

	button::after {
		border: none;
	} */

	/* #ifndef APP-NVUE */
	.set-capital {
		text-align: center;
		line-height: 30px;
		height: 30px;
		padding: 0 5px;
		right: 0;
		/* width: 30px; */
		background: #1AAD19;
		color: #FFFFFF;
		position: absolute;
		bottom: 0px;
		font-size: 12px;
	}

	.close-view {
		text-align: center;
		line-height: 14px;
		height: 16px;
		width: 16px;
		border-radius: 50%;
		background: #FF5053;
		color: #FFFFFF;
		position: absolute;
		top: -6px;
		right: -4px;
		font-size: 12px;
	}

	.uni-uploader__input-box {
		position: relative;
		width: 208upx;
		height: 208upx;
		border: 2upx solid #D9D9D9;
	}

	.uni-uploader__input {
		position: absolute;
		z-index: 1;
		top: 0;
		left: 0;
		width: 100%;
		height: 100%;
		opacity: 0;
	}

	.uni-uploader-body {
		margin-top: 16upx;
	}

	.uni-uploader__files {
		display: flex;
		flex-direction: row;
		flex-wrap: wrap;
	}

	.uni-uploader__img {
		display: block;
		width: 210upx;
		height: 210upx;
	}

	/* #endif */
</style>